﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Security;
using System.Xml;
using System.Xml.Serialization;

namespace cs2335lab5
{
    namespace Data
    {
        /// <summary>
        /// This class represents a single user in our application.
        /// </summary>
        [SerializableAttribute]
        public class User : INotifyPropertyChanged
        {
            /// <summary>
            /// Delegate to notify GUI that class elements have changed
            /// </summary>
            public event PropertyChangedEventHandler PropertyChanged;

            /// <summary>
            /// Method to notify GUI that class elements have changed
            /// </summary>
            /// <param name="propertyChanged"></param>
            public void NotifyPropertyChanged(string propertyChanged)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyChanged));
                }
            }

            /// <summary>
            /// The user's name
            /// </summary>
            private string name;
            public string Name 
            { 
                get { return name; }
                set
                {
                    name = value;
                    NotifyPropertyChanged("Name");
                }
            }

            /// <summary>
            /// The user ID
            /// </summary>
            private string id;
            public string ID 
            { 
                get { return id; }
                set
                {
                    id = value;
                    NotifyPropertyChanged("ID");
                }
            }

            /// <summary>
            /// The user's email address
            /// </summary>
            private string email;
            public string Email 
            {
                get { return email; }
                set
                {
                    email = value;
                    NotifyPropertyChanged("Email");
                }
            }

            /// <summary>
            /// The user's password
            /// </summary>
            private string password;
            public string Password
            {
                get { return password; }
                set
                {
                    password = value;
                    NotifyPropertyChanged("Password");
                }
            }

            /// <summary>
            /// Defines the access the user has to the system
            /// </summary>
            public enum Privileges { Normal, Admin };
            public Privileges? Access { get; set; }

            /// <summary>
            /// A flag true if this user is logged in correctly
            /// </summary>
            public bool isLoggedIn;

            /// <summary>
            /// A flag true if this user is online and connected
            /// </summary>
            public bool isConnected;

            /// <summary>
            /// Handler to this user's callback object
            /// </summary>
            [XmlIgnore]
            public INetworkManagerCallback Callback;

            /// <summary>
            /// Public default constructor
            /// </summary>
            public User()
            {
                this.Access = Privileges.Normal;
                this.Email = "";
                this.ID = "";
                this.Name = "";
                this.Password = "";
                isLoggedIn = false;
                isConnected = false;
            }

            /// <summary>
            /// Public parameterized constructor
            /// </summary>
            /// <param name="username"></param>
            /// <param name="password"></param>
            /// <param name="realname"></param>
            /// <param name="email"></param>
            public User(string username, string password, string realname, string email)
            {
                this.Access = Privileges.Normal;
                this.Email = email;
                this.ID = username;
                this.Name = realname;
                this.Password = password;
                isLoggedIn = false;
                isConnected = false;
            }

            public User(Data.User user)
            {
                if (user != null)
                {
                    this.Access = user.Access;
                    this.Email = user.Email;
                    this.ID = user.ID;
                    this.Name = user.Name;
                    this.Password = user.Password;
                    this.isLoggedIn = user.isLoggedIn;
                    this.isConnected = user.isConnected;
                }
            }
        }
    }
}